package cs340.stormtroopers.junitTests.phase4BlackBox;

import junit.framework.TestCase;
import cs340.stormtroopers.hypeerweb.Connections;
import cs340.stormtroopers.hypeerweb.HyPeerWeb;
import cs340.stormtroopers.hypeerweb.Node;

/**
 * Black box tests the getChildConnections method in the Connections class
 * 
 * @author Daniel Howard
 */

public class ConnectionsTest extends TestCase
{
	
	public void testGetChildConnections()
	{
		HyPeerWeb hw = HyPeerWeb.getSingleton();
		
		//Only 1 node in the HyPeerWeb
		Node newNode = new Node(0);
		hw.addToHyPeerWeb(newNode, null);
		
		Connections childConnections = newNode.getChildConnections();
		assertEquals(childConnections.getDownPointers().size(), newNode.getNeighborsBiggerThanMe().size());
		for(int i = 0; i < childConnections.getDownPointers().size(); i++)
		{
			assertEquals(childConnections.getDownPointers().get(i), newNode.getNeighborsBiggerThanMe().get(i));
		}
		
		hw.clear();
		
		
		
		//Imperfect HyPeerWeb
		for(int i = 0; i < 54; i++)
		{
			Node newNode1 = new Node(i);
			hw.addToHyPeerWeb(newNode1, null);
		}
		
		Node insertionPoint = hw.getNode(0).findEndCapNode().findInsertionPoint();
		Connections childConnections1 = insertionPoint.getChildConnections();
		assertEquals(childConnections.getDownPointers().size(), insertionPoint.getNeighborsBiggerThanMe().size());
		for(int i = 0; i < childConnections.getDownPointers().size(); i++)
		{
			assertEquals(childConnections1.getDownPointers().get(i), insertionPoint.getNeighborsBiggerThanMe().get(i));
		}
		
		hw.clear();
		
		
		
		//Perfect Hypercube
		for(int i = 0; i < 64; i++)
		{
			Node newNode2 = new Node(i);
			hw.addToHyPeerWeb(newNode2, null);
		}
		
		Node hypercubeInsertionPoint = hw.getNode(0).findEndCapNode().findInsertionPoint();
		Connections childConnections2 = hypercubeInsertionPoint.getChildConnections();
		assertEquals(childConnections2.getDownPointers().size(), hypercubeInsertionPoint.getChildConnections());
		for(int i = 0; i < childConnections2.getDownPointers().size(); i++)
		{
			assertEquals(childConnections2.getDownPointers().get(i), hypercubeInsertionPoint.getNeighborsBiggerThanMe().get(i));
		}
	}
}
